package com.xu.sms.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xu.sms.R;
import com.xu.sms.entity.Type;

public class FBOTypeAdapter extends BaseAdapter {

	private List<Type> typeList;
	private Context context;
	
	public FBOTypeAdapter() {}

	public FBOTypeAdapter(List<Type> typeList,Context context) {
		this.typeList = typeList;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return typeList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return typeList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		/* 1.复用convertView
		 * 2.得到要设置数据的控件
		 * 3.设置条目数据
		 * 4.返回视图
		 */
		View view =null;
		if(convertView !=null){
			view = convertView;
		}else{
			//得到该布局视图 然后在一次得到该布局视图的子布局
			view = View.inflate(context, R.layout.girdview_item_fbotype, null);
		}
		setWidgetData(position, view);
		return view;
	}
	//设置控件数据
	private void setWidgetData(int position, View view) {
		//自己定义的ImageView可以直接设置路径
		ImageView fbotype_iv_typeImg = (ImageView) view.findViewById(R.id.fbotype_iv_typeImg);
		TextView fbotype_tv_typeName = (TextView) view.findViewById(R.id.fbotype_tv_typeName);
		TextView fbotype_tv_typeTime = (TextView) view.findViewById(R.id.fbotype_tv_typeTime);
		
		Type type = typeList.get(position);
		fbotype_iv_typeImg.setImageResource(type.getLocalImgId());
		//fbotype_iv_typeImg.setImageURI(type.getTypeImgurl());
		fbotype_tv_typeName.setText(type.getTypeName());
		fbotype_tv_typeTime.setText(type.getTypeTimeStr());
	}
}
